package com.easy.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easy.common.bean.SeckillActivity;
import com.easy.common.service.SeckillActivityService;
import com.easy.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/seckillActivity")
public class SeckillActivityController {
    
    @Autowired
    private SeckillActivityService seckillActivityService;

    @GetMapping("{id}")
    public Result getOne(@PathVariable("id") Integer id){
        SeckillActivity seckillActivity = seckillActivityService.getById(id);
        return Result.success(seckillActivity);
    }

    @GetMapping("page")
    public Result page( SeckillActivity seckillActivity, Page page){
        QueryWrapper<SeckillActivity> queryWrapper = new QueryWrapper<>(seckillActivity);
        return Result.success(seckillActivityService.page(page, queryWrapper));
    }

    @PostMapping
    public Result save(@RequestBody SeckillActivity seckillActivity){
        return Result.success(seckillActivityService.save(seckillActivity));
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success(seckillActivityService.removeById(id));
    }

    @PutMapping
    public Result update(@RequestBody SeckillActivity seckillActivity){
        return Result.success(seckillActivityService.updateById(seckillActivity));
    }

    @GetMapping("all")
    public Result findAll(){
        return Result.success(seckillActivityService.list());
    }
}
